<template>
  <div class="login">
    <div class="box">
      {{user}}
      <h3 class="text-center h3">登录</h3>
      <el-input
        v-model="user.username"
        clearable
        placeholder="请输入用户名"
      ></el-input>
      <el-input
        v-model="user.password"
        clearable
        placeholder="请输入密码"
        show-password
      ></el-input>
      <div class="text-center">
        <el-button type="success" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { requserlogin } from '../../http/api';


export default {
  props: [],
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  computed: {
    ...mapGetters({}),
  },
  mounted() {},
  methods: {
    ...mapActions({
      "changeuserInfo":"changeuserInfo"
    }),
    // 登录
    login() {
      requserlogin(this.user).then(res=>{       
          if (res.data.code == 200) {
          // 给vuex和本地存储都存一份数据
          this.changeuserInfo(res.data.list)
            this.$router.push("/")
          }
      })
    },
  },
};
</script>

<style scoped lang="less">
@import "../../less/index.less";

.login {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @primary-light, @primary-deep);
  position: relative;
}
.box {
  width: 400px;
  background: #fff;
  padding: @padding20;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: @padding10;
  .el-input {
    margin-bottom: @margin20;
  }
}
</style>